/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ticketmaster.businesslogic;

import java.sql.Timestamp;
import java.util.Calendar;
import java.util.Collection;
import ticketmaster.common.OrderType;
import ticketmaster.dao.DAOFactory;
import ticketmaster.dao.OrderDAO;
import ticketmaster.dataobject.Event;
import ticketmaster.dataobject.Order;
import ticketmaster.util.DateTimeHelper;

/**
 *
 * @author Wei Liu
 */
public class OrderController
{

    public int createOrder(Order order)
    {
        OrderDAO orderDAO = DAOFactory.getInstance().getOrderDAO();
        return orderDAO.insertOrder(order);
    }

    public boolean updateOrder(Order order)
    {
        OrderDAO orderDAO = DAOFactory.getInstance().getOrderDAO();
        return orderDAO.updateOrder(order);
    }

    public int createYearlyFeeOrder(int customerID)
    {
        Collection<Event> events = DAOFactory.getInstance().getEventDAO().getEventsDO(new Event());
        Event event = new Event();
        for (Event item : events)
        {
            if (item.getName().equals("Yearly Fee"))
            {
                event = item;
                break;
            }
        }

        Order order = new Order();
        order.setCost(100);
        order.setCustomerID(customerID);
        Calendar cal = DateTimeHelper.getCurrentDateTimeCalendar();
        cal.add(Calendar.DAY_OF_YEAR, 10);
        order.setDueDate(new Timestamp(cal.getTimeInMillis()));
        order.setOrderDate(DateTimeHelper.getCurrentDateTime());
        order.setOrderType(OrderType.YearlyFee.ordinal());
        order.setEventID(event.getEventID());

        OrderDAO orderDAO = DAOFactory.getInstance().getOrderDAO();
        return orderDAO.insertOrder(order);
    }
}
